<?php

namespace App\Models;

use App\Models\Member\Member;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Traits\ModelTree;
use Illuminate\Database\Eloquent\Model;
use Encore\Admin\Traits\DefaultDatetimeFormat;

class Work extends Model
{
    use DefaultDatetimeFormat, ModelTree;

    protected $table = 'work';

    public $sortable = [
        'order_column_name' => 'order',
        'sort_when_creating' => true,
    ];

    // 允许大量赋值的字段
    protected $fillable = ['member_id', 'org_id', 'year', 'target', ];

    public static function grid($callback)
    {
        return new Grid(new static, $callback);
    }

    public static function form($callback)
    {
        return new Form(new static, $callback);
    }

    public function member()
    {
        return $this->belongsTo(Member::class, 'member_id', 'id');
    }

    public function org()
    {
        return $this->belongsTo(Org::class, 'org_id', 'id');
    }

}
